package cn.xmy.demo01.controller;

import cn.xmy.demo01.pojo.Address;
import cn.xmy.demo01.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.sql.SQLException;
import java.util.List;

@Controller
public class AddAddressController {
@Autowired
    AddressService addressService;
    @GetMapping("/add")
    public String add(){
        return "address";
    }

    @PostMapping("/add")
    public String add(Address address) throws SQLException, ClassNotFoundException {
        addressService.addAddress(address);
        return "redirect:/address";
    }
    @RequestMapping("index")
    public String select(Model model) throws SQLException, ClassNotFoundException {
        List<Address> select = addressService.findAllAddress();
        model.addAttribute("select",select);
        return "index";
    }

}
